
= simple_form_for(@order_maintain_item, html: {class: 'form-vertical', novalidate: true}, wrapper: :vertical_form) do |o|
  .row
	  .col-md-12.hidden
	    = o.input :order_maintain_id, input_html: { value: params[:id] }
	  .col-md-12
	    = o.input :maintain_style_id, collection: @maintain_styles, as: :collection_select, label: '分类'

	    = o.input :maintain_item_id, collection: @maintain_styles, as: :grouped_collection_select, group_method: :maintain_items, label: '维修项目'

	    = o.button :submit, "保存", :class => 'btn-success btn-xs'

coffee:
  jQuery ->
    $('#order_maintain_item_maintain_item_id').parent().hide()
    maintain_items = $('#order_maintain_item_maintain_item_id').html()
    $('#order_maintain_item_maintain_style_id').change ->
      maintain_style = $('#order_maintain_item_maintain_style_id :selected').text()
      escaped_maintain_style = maintain_style.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
      options = $(maintain_items).filter("optgroup[label='#{escaped_maintain_style}']").html()
      if options
        $('#order_maintain_item_maintain_item_id').html(options)
        $('#order_maintain_item_maintain_item_id').parent().show()
      else
        $('#order_maintain_item_maintain_item_id').empty()
        $('#order_maintain_item_maintain_item_id').parent().hide()
